;
(function() {
  new Vue({
    el: '#notice',
    data: {
      flag: true,
      orders: '#',
      columns: '#',
      pagetotal: 0,
      page: 1,
      limit: ['10'],
      pageCounts: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
      modulesList: [],
      typeStatus: '',
      keyword: '',
      user: '',
      moduleId: '#',
      data: [],
      quanxian: JSON.parse(window.localStorage.getItem('permissions')),
    },
    filters: {
      framtTime(time) {
        return hlDateUtil.formatDate(time, 'yyyy-MM-dd HH:mm:ss')
      },
      formatDate: function(time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
    },
    methods: {
			//展示数量
			eventPage(arr) {
			  this.limit = [arr[0].code]
			  this.getListData()
			},
      //显示隐藏查询条件
      showHideTerm() {
        this.flag = !this.flag;
      },
      // 设置背景色
      addbgcolor(index) {
        let el = document.querySelectorAll('.house-two-tone');
        let el0 = document.querySelectorAll('.house-operate')
        el[index].classList.add('house-two-tone-hover')
        el0[index].classList.add('house-two-tone-hover')
      },
      //删除背景色
      removebgcolor(index) {
        let el = document.querySelectorAll('.house-two-tone');
        let el0 = document.querySelectorAll('.house-operate')
        el[index].classList.remove('house-two-tone-hover')
        el0[index].classList.remove('house-two-tone-hover')
      },
      //最后更新时间
      updateTime() {
        setTimeout(() => {
          this.getListData()
        }, 300)
        if (this.columns != 'UT') {
          this.columns = 'UT';
          this.orders = 'A';
          return
        }
        if (this.orders == 'A') {
          this.orders = 'D'
          return
        }
        if (this.orders == 'D') {
          this.orders = 'A'
          return
        }
      },
      //创建时间
      createTime() {
        setTimeout(() => {
          this.getListData()
        }, 300)
        if (this.columns != 'CT') {
          this.columns = 'CT';
          this.orders = 'A';
          return
        }
        if (this.orders == 'A') {
          this.orders = 'D'
          return
        }
        if (this.orders == 'D') {
          this.orders = 'A'
          return
        }
      },
      //新建/编辑负责人
      header_create_edit(type, id) {
        if (type == 'add') {
          hlUrlUtil.goTo('jwkExclusiveServiceCreate', {
            ddtab: true,
            type: type
          }, true)
          return
        }
        hlUrlUtil.goTo('jwkExclusiveServiceCreate', {
          ddtab: true,
          type: type,
          id: id
        }, true)
      },
      //重置
      reset() {
        this.keyword = '';
        this.moduleId = '#';
        this.orders = 'ASC';
        this.columns = 'CT';
        this.page = 1;
        this.limit = ['10'];
        this.getListData()
      },
      //查询
      search() {
        this.page = 1
        this.limit = ['10'];
        this.getListData();
      },
      //获取专属服务列表
      getListData() {
        hlhttp.get({
          url: 'jwk/exclusive_services',
          data: {
            'keyword': this.keyword || '#',
            'create_user_name': this.user || '#',
            'order': this.orders,
            'column': this.columns,
            'page': this.page,
            'page_count': this.limit[0]
          },
          success: (data) => {
            this.data = data
            // this.searchTop(data)
            $("#page").initPage(data.totalPage, this.page, (n) => {
              if (this.page == n) {
                return
              }
              this.page = n;
              this.getListData();
            });
          }
        })
      },
      // 查找置顶项然后重新排序
      searchTop(data) {
        var obj = ''
        data.services.some((item, index) => {
          if (item.topFlag == 'Y') {
            obj = item
            data.services.splice(index, 1)
            data.services.unshift(obj)
          }
        })

      },
      // 置顶前判断是否有弹框
      toTop(id, flag) {
        if (flag == 'Y') {
          this.sureTotop(id, 'N')
        } else {
          var that = this
          for (let i = 0; i < that.data.services.length; i++) {
            if (that.data.services[i].topFlag == 'Y') {
              hllayer.confirm1('当前已存在置顶公告，继续置顶将取消已置顶的服务', function() {
                that.sureTotop(id, 'Y')
              })
              return
            }
          }
          that.sureTotop(id, 'Y')
        }
      },
      //置顶的方法
      sureTotop(id, flag) {
        var that = this
        hlhttp.put({
          url: 'jwk/exclusive_service/_top',
          data: {
            'exclusive_service_id': id,
            'opt': flag
          },
          success: (data) => {
            hl.toast('操作成功')
            that.getListData()
          }
        })
      },
      //删除
      delItem(id) {
        hllayer.confirm('确认要删除该服务吗?', () => {
          hlhttp.delete({
            url: 'jwk/exclusive_service?exclusive_service_id=' + id,
            data: {
              'exclusive_service_id': id,
            },
            success: (data) => {
              hl.toast('操作成功')
              this.getListData()
            }
          })
        })
      }
    },
    created() {
      hlSelectUi()
    },
    mounted() {
      this.getListData()
    }
  })
}())
